package com.COMP3111H.project;

import android.app.Activity;
import android.content.SharedPreferences;
import android.util.Log;

public class LoginUtility {

	protected static String[] getUsernamePassword(Activity a) {
		SharedPreferences dhj;
		dhj = a.getSharedPreferences("bookwarm",
				android.content.Context.MODE_PRIVATE);

		if (dhj != null) {
			String username = dhj.getString("username", null);
			if (username != null) {
				String password = dhj.getString("password", null);
				String[] usernameAndPassword = new String[2];
				usernameAndPassword[0] = username;
				usernameAndPassword[1] = password;
				return usernameAndPassword;
			}
		}
		return null;
	}
	
	protected static boolean checkLoginStatus(Activity a){
		SharedPreferences dhj;
		dhj = a.getSharedPreferences("bookwarm",
				android.content.Context.MODE_PRIVATE);

		if (dhj != null) {
			String username = dhj.getString("username", null);
			if (username != null) {
				Log.v("Bookwarm", "username-"+username);
				return true;
			}
		}
		return false;
	}
	

	protected static void logout(Activity a) {
		SharedPreferences dhj;
		dhj = a.getSharedPreferences("bookwarm", android.content.Context.MODE_PRIVATE); 
		SharedPreferences.Editor dhjEditor = dhj.edit(); 
		dhjEditor.remove("username"); 
        dhjEditor.remove("password"); 
        dhjEditor.commit(); 
	}
	
}